package com.example.controller;

import com.example.common.Result;
import com.example.entity.Address;
import com.example.entity.Articles;
import com.example.entity.HistoryThings;
import com.example.service.ArticlesService;
import com.example.service.HistoryThingsService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 历史文物前端接口
 */
@RestController
@Api(value = "历史文物", tags = {"历史文物的增删改查"})
@RequestMapping("/historythings")
public class HistoryThingsController {

    @Resource
    private HistoryThingsService historyThingsService;

    /**
     * 新增
     */
    @ApiOperation(value = "增加文物", notes = "返回是否成功")
    @PostMapping("/add")
    public Result add(@RequestBody HistoryThings historyThings) {
        historyThingsService.add(historyThings);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除历史文物", notes = "返回是否成功")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "id",
                    value = "要删除的历史文物id,如'1'"
            )
    })
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        historyThingsService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除历史文物", notes = "返回是否成功")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        historyThingsService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新历史文物信息", notes = "返回是否成功")
    @PutMapping("/update")
    public Result updateById(@RequestBody HistoryThings historyThings) {
        historyThingsService.updateById(historyThings);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "通过id查询历史文物", notes = "返回Models中的历史文物类型")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "id",
                    value = "要查询的历史文物id,如'1'"
            )
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = HistoryThings.class,reference = "HistoryThings")
    })
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        HistoryThings historyThings = historyThingsService.selectById(id);
        return Result.success(historyThings);
    }

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有符合特征的历史文物信息", notes = "返回Models中的历史文物信息类型的数组")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = HistoryThings.class,reference = "HistoryThings")
    })
    @GetMapping("/selectAll")
    public Result selectAll(HistoryThings historyThings ) {
        List<HistoryThings> historyThingsList= historyThingsService.selectAll(historyThings);
        return Result.success(historyThingsList);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询所有符合特征的历史文物", notes = "返回Models中的历史文物信息的分页数组")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "pageNum",
                    value = "要查询的页码,默认为'1'"
            ),
            @ApiImplicitParam(
                    name = "pageSize",
                    value = "每页尺寸,默认为'10'"
            )
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = HistoryThings.class,reference = "HistoryThings")
    })
    @GetMapping("/selectPage")
    public Result selectPage(HistoryThings historyThings,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<HistoryThings> pageInfo = historyThingsService.selectPage(historyThings, pageNum, pageSize);
        return Result.success(pageInfo);
    }

}
